﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Pku.BookStore.IServices;
using Pku.BookStore.Model;

namespace Pku.BookStore.Services
{
    [Serializable]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode.Multiple)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CategoryServices : ICategoryServices
    {
        /// <summary>
        /// 获取实例名
        /// </summary>
        private DAL.CategoryDAL categoryDAL
        {
            get
            {
                return new DAL.CategoryDAL();
            }
        }

        /// <summary>
        /// 增加分类
        /// </summary>
        /// <param name="entity"></param>
        public int Add(CategoryModel entity)
        {
            return categoryDAL.Add(entity);
        }

        /// <summary>
        /// 修改分类
        /// </summary>
        /// <param name="entity"></param>
        public bool Modify(CategoryModel entity)
        {
            return categoryDAL.Modify(entity);
        }

        /// <summary>
        /// 搜索
        /// </summary>
        /// <returns></returns>
        public List<CategoryModel> Search(Model.CategoryParam param)
        {
            return categoryDAL.Search(param);
        }

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="categoryID"></param>
        /// <returns></returns>
        public CategoryModel GetEntityById(int categoryID)
        {
            return categoryDAL.GetEntityById(categoryID);
        }

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="Str">关键字</param>
        /// <returns></returns>
        public bool Exist(string Str)
        {
            return categoryDAL.Exist(Str);
        }

        /// <summary>
        /// 获取总数
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int GetCount(Model.CategoryParam param)
        {
            return categoryDAL.GetCount(param);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="CategoryID"></param>
        /// <returns></returns>
        public bool Delete(int CategoryID)
        {
            return categoryDAL.Delete(CategoryID);
        }

        /// <summary>
        /// 取同级分类
        /// </summary>
        /// <param name="Level"></param>
        /// <param name="pCatid"></param>
        /// <returns></returns>
        public List<CategoryModel> GetLevelSame(int Level, int pCatid)
        {
            return categoryDAL.GetLevelSame(Level, pCatid);
        }
    }
}
